package com.citywithincity.db.drivers.oracle;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.citywithincity.db.Db;
import com.citywithincity.db.Record;
import com.citywithincity.utils.DataUtil;

public class OracleSqlHelper {

	/**
	 * 修改表注释的语句
	 * @param tableName
	 * @param comment
	 * @return
	 */
	public static String alterTableComment(String tableName, String comment){
		return String.format("comment on table %s is '%s';",tableName,comment);
	}

	/**
	 * 修改字段注释
	 * @param tableName
	 * @param column
	 * @param comment
	 * @return
	 */
	public static String alertColumnComment(String tableName, String column,  String comment){
		//保存进入memcached
		return String.format("comment on column %s.%s is '%s';",tableName,column,comment);
	}
	
	private static final Log logger = LogFactory.getLog(OracleSqlHelper.class);
	
	/**
	 * 
	 * @param key
	 * @return
	 */
	public static long nextVal(String sequence){
		List<Record> records = Db.ar().query(String.format("SELECT %s.NEXTVAL AS VAL FROM DUAL", sequence));
		//logger.info("SEQUENCE:"+records);
		
		Record record = records.get(0);
		
		return DataUtil.toLong(record.get("VAL"));
	}
}
